﻿using BookManage.BLL;
using BookManage.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BookManage
{
    public partial class frmPayPunish : Form
    {
        Borrow borrow = new Borrow();
        Reader reader = new Reader();
        private DataTable dt = null;
        private BorrowAdmin borrowBLL = new BorrowAdmin();
        public frmPayPunish()
        {
            InitializeComponent();
        }
        private void ShowBorrowData()
        {
            dgvBorrow.DataSource = dt;
            foreach (DataColumn dc in dt.Columns)
            {
                dgvBorrow.Columns[dc.ColumnName].HeaderText = Borrow.ColumnTitle(dc.ColumnName);
            }
        }
        private void SelectBk_Click(object sender, EventArgs e)
        {
            Borrow borrow = new Borrow();
            int rdID = Convert.ToInt32(txtrdID.Text);
            int bkID = Convert.ToInt32(txtbkID.Text);
            dt = borrowBLL.GetBorrow(bkID);
            ShowBorrowData();
            borrow.IdDateRetAct = DateTime.Now;//还书日期
            borrow = BorrowAdmin.GetAllBorrow(rdID, bkID);
            MessageBox.Show("您的应罚款金额为：" + borrow.IdOverMoney);
        }

        private void btnPay_Click(object sender, EventArgs e)
        {
            int rdID = Convert.ToInt32(txtrdID.Text);
            int bkID = Convert.ToInt32(txtbkID.Text);
            DateTime IdDateRetPlan = DateTime.Now.AddDays(1);
            if (txtrdID.Text == "" || txtbkID.Text == ""|| txtPay.Text=="")
                MessageBox.Show("缴纳罚款请输入读者号和书号！！！");
            else
            {
                float IdPunishMoney = Convert.ToSingle(txtPay.Text);
                MessageBox.Show(Convert.ToString(IdPunishMoney));
                borrow = BorrowAdmin.GetAllBorrow(rdID, bkID);
                if (borrow.IdOverMoney!= IdPunishMoney)
                {
                    MessageBox.Show("您缴纳的金额小于应缴纳金额，请一次交清完毕！！！");
                    MessageBox.Show("您的应罚款金额为：" + borrow.IdOverMoney);
                }
                else
                {
                    BorrowAdmin.UpdatePunish(rdID, bkID, IdPunishMoney, IdDateRetPlan);
                    MessageBox.Show("您缴纳金额：" + borrow.IdPunishMoney + "已缴清应罚金额！务必在今天之内归还超期图书");
                }
            }
        }
        private void btnBack_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnLend_Click(object sender, EventArgs e)
        {
        }
    }
}
